﻿Ext.define('app.system.document_type.Index',
{
    extend: 'Ext.grid.Panel',
    border: true,
    title: localize('DocumentType'),
    viewConfig: {
        enableTextSelection: true //可以复制单元格文字
    },
    multiColumnSort: true,
    forceFit: true,
    initComponent: function () {
        var me = this;

        me.tbar = [
            {
                text: localize('Add'), iconCls: "add", handler: function () {
                    var win = Ext.create("app.system.document_type.Edit", { title: '新增分类' });
                    win.on("savesuccess", function () {
                        me.store.load();
                        win.close();
                    });
                    win.show();
                }
            },
            '->',
            {
                text: '保存排序',
                icon: '/Content/images/page_save.png',
                handler: function () {
                    var arry = [];
                    var store = me.store;
                    for (var i = 0; i < store.getCount() ; i++) {
                        var record = store.getAt(i);
                        arry.push({ key: record.data.id, value: record.data.orderNo });
                    }
                    if (arry.length == 0) {
                        Ext.Msg.alert('系统提示', "没有需要保存的数据");
                        return false;
                    }
                    App.AjaxPost('/api/services/app/documentType/EditDocumentTypeOrder', arry, function (data) {
                        me.store.load();
                    });
                }
            }
        ];


        me.store = Ext.create("app.ux.PrmStore", { url: '/api/services/app/documentType/GetAll' });
        me.callParent(arguments);
    },
    plugins: [
        Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 })
    ],
    columns: [
        {
            xtype: 'actioncolumn',
            width: 70,
            header: localize('Operating'),
            items: [
            {
                iconCls: 'edit',
                tooltip: localize('Edit'),
                handler: function (grid, rowIndex, colIndex) {
                    var record = grid.store.getAt(rowIndex);
                    var win = Ext.create("app.system.document_type.Edit", { title: '编辑分类', isSystem: record.data.isSystem, documentTypeId: record.data.id });
                    win.on("savesuccess", function () {
                        grid.store.load();
                        win.close();
                    });
                    win.show();
                },
                getClass: function (v, meta, rec) {
                    if (rec.data.isSystem) {
                        return 'x-hidden'
                    } else {
                        return 'edit'
                    }
                }
            }]
        },
        {
            header: localize('IsEnabled'), dataIndex: 'isEnabled', renderer: function (value, p, record) {
                return value ? "可用" : "不可用";
            }
        },
        { header: localize('RootName'), dataIndex: 'rootName' },
        { header: localize('ParentName'), dataIndex: 'parentName' },
        { header: localize('TypeName'), dataIndex: 'name' },
        { header: '默认上传个数', dataIndex: 'defaultUploadNum' },
        { header: localize('Description'), dataIndex: 'description' },
        { header: localize('Sortfactor'), dataIndex: 'orderNo', editor: {} }
    ]
});
